package com.xzy.sms.web.domain.dao;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.xzy.sms.web.domain.entity.Application;

/**
 * @desc 用户DAO
 * @author wjw
 * @time 2017年11月16日下午3:32:26
 */
public interface ApplicationDao extends JpaRepository<Application, String>, JpaSpecificationExecutor<Application> {
    
    /**
     * 获取某个用户的所有应用
     * 
     * @param userId id
     * @param pageable xx
     * @return xx
     */
    @Query("select t from Application t where t.user.userId=?1 ")
    Page<Application> findByUserId(String userId, Pageable pageable);
    
    /**
     * 逻辑删除应用
     * @param applicationId xx
     */
    @Modifying
    @Query("update Application set delFlag='1' where applicationId=?1 ")
    void setDelFlag(String applicationId);
    
    /**
     * 获取某个用户的所有应用
     * 
     * @param userId id
     * @param pageable xx
     * @return xx
     */
    @Query("select t from Application t where t.delFlag='0' and t.user.userId=?1 ")
    List<Application> findByUserId(String userId);
    
}